package com.grace.cms.general.service.search;

import java.util.List;

import com.grace.cms.common.domain.entity.CmsColumn;
import com.grace.cms.common.enums.CommonVisibleEnums;
import com.grace.cms.general.service.IGeneralSearchService;
import com.grace.cms.query.mapper.ColumnSearchMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GeneralColumnServiceImpl implements IGeneralSearchService {
    @Autowired
    private ColumnSearchMapper columnSearchMapper;

    public CmsColumn selectCmsColumnById(long columnId) {
        return columnSearchMapper.selectCmsColumnById(getPm(columnId));
    }

    public List<CmsColumn> listCmsColumn(CmsColumn cmsColumn) {
        cmsColumn=cmsColumn==null?new CmsColumn():cmsColumn;
        cmsColumn.setVisible(CommonVisibleEnums.SHOW.ordinal());
        return columnSearchMapper.listCmsColumns(cmsColumn);
    }

    /**
     * 获取节点及所有子节点
     * 
     * @param columnId
     * @return
     */
    public List<CmsColumn> listCmsColumnById(long columnId) {
        return this.listCmsColumn(getPm(columnId));
    }


    private CmsColumn getPm(long columnId){
        CmsColumn cmsColumn = new CmsColumn();
        cmsColumn.setVisible(CommonVisibleEnums.SHOW.ordinal());
        cmsColumn.setColumnId(columnId);
        return cmsColumn;
    }

}
